/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
**/
define("pages/jcjl/jcjl_dynamic", [
        "../../common/componts.js",
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate"
    ],
    function(require) {
        var componts = require("../../common/componts");
        var queryTableId="awdDynamicQueryTableId";
        var selectid;

        var getQueryDataGrid = function(){
            return $("#"+queryTableId);
        };

        var tableInit=function(){
            componts.initTable(queryTableId,{
                url:"/jcjl/list",
                title:'',
                fit:true,
                // firstLoad:true,
                width:'100%',
                columns :  [
                    {field: 'id',title: '',width:30,hidden:true}
                    ,{field:'zxr',title:'执行人',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'sldsprq',title:'所领导审批日期',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'tbrq',title:'填报日期',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'sld',title:'所领导',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'cpgj',title:'呈批管教',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'cprq',title:'呈批日期',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ly',title:'奖惩原因',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gjzyj',title:'管教组意见',width:60,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'bz',title:'备注',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                ] ,
                //基本信息双击事件
                onDblClickRow:function(rowIndex, rowData){
                    $("input[name='ryRadio']")[rowIndex].checked = true;
                    getQueryDataGrid().datagrid("selectRow", rowIndex);
                    selectid=rowData.id;
                },
                onLoadSuccess:function(data){
                    if(data.total>0){
                        getQueryDataGrid().datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }
                },
                //单击行选中取消事件
                onClickRow:function(rowIndex, rowData){
                    if(selectid!=rowData.id){
                        $("input[name='ryRadio']")[rowIndex].checked = true;
                        selectid=rowData.id;
                    }else{
                        getQueryDataGrid().datagrid("unselectRow",rowIndex);
                        $("input[name='ryRadio']")[rowIndex].checked = false;
                        getQueryDataGrid().datagrid('clearSelections');
                        selectid="";
                    }
                }
                });
                //页面高度自适应
                getQueryDataGrid().datagrid('resize',{
                    height:($(window).height()-150)
                });
            };

        /**
         * 数据列表刷新加载
         */
        var loadDataGrid = function(){
            var formData = $(".awd-dynamic-query-form").serializeObject();
            var queryParams = $.extend({},formData,{"state":"R2"});
            getQueryDataGrid().datagrid('clearSelections');
            getQueryDataGrid().datagrid('load',queryParams);
        };

        var bindAction=function(){
            //查询
            $(".awd-dynamic-query-btn").on("click",function(){
                loadDataGrid();
            });

            /**
             * 绑定回车事件
             */
            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    loadDataGrid();
                }
            });

        };

        //初始化
        (function(){
            componts.initSelectPage(undefined);
            componts.initSelect(undefined,undefined,undefined);
            tableInit();
            bindAction();
        })()
    });
